package com.yjx.util;

import org.springframework.util.DigestUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class PasswordUtil {

    public static Map<String,String> getMD5PassWord(String password){
        //加密
        //随机生成一个salt
        String uuid= UUID.randomUUID().toString();
        uuid = uuid.substring(uuid.length() - 6);
        //password md5->password1
        String pasword1 = DigestUtils.md5DigestAsHex(password.getBytes());
        //salt+password1 md5-> password2
        String password2 = DigestUtils.md5DigestAsHex((uuid + pasword1).getBytes());
        Map<String,String> map= new HashMap<>();
        map.put("password",password2);
        map.put("salt",uuid);
        return map;
    }

    public static String getFormerPWD(String password,String Salt) {
        //password md5->password1
        String pasword1 = DigestUtils.md5DigestAsHex(password.getBytes());
        //salt+password1 md5-> password2
        return DigestUtils.md5DigestAsHex((Salt + pasword1).getBytes());
    }



}
